<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inv_uom extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
		
	}

	public function index(){

	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'));
	  $this->load->view('layouts/footer');
	}

	public function search_uom(){
		$uom_code = $this->input->post('uomCode');
		$uom_name = $this->input->post('uomName');

		$query = $this->inv_uom_model->search_uom($uom_code, $uom_name);

		if(!empty($query)) {
			echo json_encode($query);
		}else{
			echo json_encode("none");
		}

	}
	
	public function insert_uom(){
	 	$ena = $this->input->post('uom_enabler');
	 	$data = array(
	 		':p_trx_type'		=> 'I',
	 		':p_company_id'		=> $this->input->post('company_id'),
	 		':p_uom_code'		=> $this->input->post('uom_code'),
	 		':p_uom_name'		=> $this->input->post('uom_name'),
	 		':p_enable_flag'	=> ($ena == "ok" ? 'Y' : 'N'),
	 		':p_user_id'		=> $this->session->userdata('user_id'),
	 		':p_uom_id'			=> ''
	 		);
	 	$this->inv_uom_model->insert_uom($data);
	 }
	 public function update_uom(){
	 	$ena = $this->input->post('e_uom_enabler');
	 	$data = array(
	 		':p_trx_type'		=> 'U',
	 		':p_company_id'		=> $this->input->post('e_company_id'),
	 		':p_uom_code'		=> $this->input->post('e_uom_code'),
	 		':p_uom_name'		=> $this->input->post('e_uom_name',TRUE),
	 		':p_enable_flag'	=> ($ena == "ok" ? 'Y' : 'N'),
	 		':p_user_id'		=> $this->session->userdata('user_id'),
	 		':p_uom_id'			=> $this->input->post('e_uom_id')
	 		);

	 	$this->inv_uom_model->edit_uom($data);
	 }



	public function add_form(){
		$this->load->view($this->session->userdata('foradd'));
	}
	public function edit_form($id){
		$result = $this->inv_uom_model->get_uom($id);
		$this->load->view($this->session->userdata('foredit'),array(
				'result'	=>$result
		));
	}
	public function view_form($id){
		$result = $this->inv_uom_model->get_uom($id);
		$this->load->view($this->session->userdata('forview'),array(
				'result'	=>$result
		));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */